package com.usian.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.usian.admin.mapper.AdSensitiveMapper;
import com.usian.admin.service.AdSensitiveService;
import com.usian.model.admin.dtos.SensitiveDto;
import com.usian.model.admin.pojos.AdSensitive;
import com.usian.model.common.dtos.PageResponseResult;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import org.springframework.stereotype.Service;

/**
 * @author baimugudu
 * @email 2415621370@qq.com
 * @date 2023/8/23 14:46
 */
@Service
public class AdSensitiveServiceImpl extends ServiceImpl<AdSensitiveMapper,AdSensitive> implements AdSensitiveService {

    @Override
    public ResponseResult findSensitive(SensitiveDto sensitiveDto) {
        if(null==sensitiveDto){
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }

        sensitiveDto.checkParam();

        IPage page = new Page<AdSensitive>(sensitiveDto.getPage(), sensitiveDto.getSize());
        QueryWrapper<AdSensitive> adSensitiveQueryWrapper = new QueryWrapper<>();
        if(sensitiveDto.getName()!=null){
            adSensitiveQueryWrapper.lambda().eq(AdSensitive::getSensitives,sensitiveDto.getName());
        }
        IPage page1 = this.page(page, adSensitiveQueryWrapper);

        ResponseResult responseResult = new PageResponseResult(sensitiveDto.getPage(), sensitiveDto.getSize(), (int) page1.getTotal());
        responseResult.setData(page1.getRecords());

        return responseResult;
    }
}
